using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System;
using Microsoft.Xna.Framework.GamerServices;
using TestGame.GameLib;

namespace TestGame {
    /// <summary>
    /// The Main class that incorporates all the classes in the Game.
    /// </summary>
    public class MyGame : Game {
        #region Fields

        /// <summary>
        /// Used for displaying graphical content.
        /// </summary>
        GraphicsDeviceManager graphics;

        /// <summary>
        /// Used to keep track of all the Screens in the game.
        /// </summary>
        ScreenManager screenManager;

        #endregion

        #region Properties

        /// <summary>
        /// The port number used in the multiplayer sessions of the game.
        /// </summary>
        public const int Port = 20785;

        #endregion

        #region Initialization

        /// <summary>
        /// The main game constructor.
        /// </summary>
        public MyGame() {
            Content.RootDirectory = "Content";

            // Set Game Settings
            this.IsMouseVisible = true;

            // Set Audio Settings
            MediaPlayer.IsRepeating = true;
            UpdateSoundSettings();
            
            // Set Graphics Settings
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 880;
            graphics.PreferredBackBufferHeight = 660;
            
            if (Options.Default.full_screen) {
                graphics.ToggleFullScreen();
            }
            
            // Create the screen manager component.
            screenManager = new ScreenManager(this, graphics);
            Components.Add(screenManager);

            // Activate the first screens.
            screenManager.AddScreen(new BackgroundScreen(), null);
            screenManager.AddScreen(new MainMenuScreen(), null);
        }

        /// <summary>
        /// Loads content designated by the preloaded assets.
        /// </summary>
        protected override void LoadContent() {
            Content.Load<object>("gradient");
        }

        /// <summary>
        /// Updates the MediaPlayer and SoundEffect volume according the the
        /// options.settings file.
        /// </summary>
        public static void UpdateSoundSettings() {
            MediaPlayer.Volume = Options.Default.master_volume * Options.Default.music_volume;
            SoundEffect.MasterVolume = Options.Default.master_volume * Options.Default.sfx_volume;
        }

        #endregion
    }

    /// <summary>
    /// The main entry point for the Game
    /// </summary>
    static class Program {
        [STAThread]
        static void Main() {
            using (MyGame game = new MyGame()) {
                game.Run();
            }
        }
    }
}
